package com.demo.test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.demo.common.feign.UserFeign;
import com.demo.test.entity.ServiceName;
import com.demo.test.mapper.ServiceNameMapper;
import com.demo.test.service.ServiceNameService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * ServiceName 服务实现类
 *
 * @author YT
 * @date 2019-05-16
 */
@AllArgsConstructor
@Service
@Transactional(readOnly = true, rollbackFor = Exception.class)
public class ServiceNameImpl extends ServiceImpl<ServiceNameMapper, ServiceName> implements ServiceNameService {

    private final UserFeign userFeign;

    @Override
    @LcnTransaction
    @Transactional(readOnly = false, rollbackFor = Exception.class)
    public void testLcn() {
        ServiceName serviceName = new ServiceName();
        serviceName.setName("test-service");
        this.insertTestServiceName(serviceName);
        userFeign.saveUser();
        int a = 1 / 0;
    }

    @Override
    @Transactional(readOnly = false, rollbackFor = Exception.class)
    public void insertTestServiceName(ServiceName serviceName) {
        baseMapper.insert(serviceName);
    }

    @Override
    public List<ServiceName> serviceNameList(ServiceName serviceName) {
        QueryWrapper<ServiceName> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(serviceName);
        return baseMapper.selectList(queryWrapper);
    }
}
